#include <stdio.h>
#include "single_linked_list.cpp"
#include <map>
using namespace std;

// 求B是否是A的子序列
bool IsSubsquence(LinkedList A, LinkedList B) {
    map<int,bool> mp;
    int lengthA = 0;
    while (A->next){
        mp[A->next->data] = true;
        A = A->next;
        lengthA++;
    }
    int lengthB = 0;
    while (B->next) {
        if (lengthB > lengthA)
            return false;
        if (mp.find(B->next->data) == mp.end()) {
            return false;
        }
        B = B->next;
        lengthB++;
    }   
    
    return true;
}

int main() {
    LinkedList L1;
    InitList(L1);

    LinkedList L2;
    InitList(L2);

    // 插入
    ListAppend(L1, 0);
    ListAppend(L1, 3);
    ListAppend(L1, 7);
    ListAppend(L1, 10);
    PrintList(L1);

    ListAppend(L2, 0);
    ListAppend(L2, 3);
    ListAppend(L2, 5);
    PrintList(L2);

    bool flag = IsSubsquence(L1,L2);
    printf("===> %d\n", flag);
    
    return 0;
}